 package client;

 import configs.ServerConfig;
 import constants.GameConstants;
 import tools.MaplePacketCreator;

 public class MapleTrait
 {
   private MapleTraitType type;
/*  10 */   private int totalExp = 0; private int localTotalExp = 0;
/*  11 */   private short exp = 0;
/*  12 */   private byte level = 0;


   public MapleTrait() {}


   public MapleTrait(MapleTraitType traitTyp) {
/*  19 */     this.type = traitTyp;
   }

   public void setExp(int exp, MapleCharacter chr) {
/*  23 */     if (exp >= 0) {
/*  24 */       this.totalExp = exp;
/*  25 */       this.localTotalExp = exp;
/*  26 */       chr.updateSingleStat(this.type.getStat(), this.totalExp);
/*  27 */       chr.send(MaplePacketCreator.showTraitGain(this.type, exp));
/*  28 */       recalcLevel();
     }
   }

   public void addExp(int exp) {
/*  33 */     this.totalExp += exp;
/*  34 */     this.localTotalExp += exp;
/*  35 */     if (exp != 0) {
/*  36 */       recalcLevel();
     }
   }

   public void addExp(int exp, MapleCharacter chr) {
/*  41 */     addTrueExp(exp * ServerConfig.CHANNEL_RATE_TRAIT, chr);
   }

   public void addTrueExp(int exp, MapleCharacter chr) {
/*  45 */     if (exp != 0) {
/*  46 */       this.totalExp += exp;
/*  47 */       this.localTotalExp += exp;
/*  48 */       chr.updateSingleStat(this.type.getStat(), this.totalExp);
/*  49 */       chr.send(MaplePacketCreator.showTraitGain(this.type, exp));
/*  50 */       recalcLevel();
     }
   }

   public boolean recalcLevel() {
/*  55 */     if (this.totalExp < 0) {
/*  56 */       this.totalExp = 0;
/*  57 */       this.localTotalExp = 0;
/*  58 */       this.level = 0;
/*  59 */       this.exp = 0;
/*  60 */       return false;
     }
/*  62 */     int oldLevel = this.level;
/*  63 */     for (byte i = 0; i < 100; i = (byte)(i + 1)) {
/*  64 */       if (GameConstants.getTraitExpNeededForLevel(i) > this.localTotalExp) {
/*  65 */         this.exp = (short)(GameConstants.getTraitExpNeededForLevel(i) - this.localTotalExp);
/*  66 */         this.level = (byte)(i - 1);
/*  67 */         return (this.level > oldLevel);
       }
     }
/*  70 */     this.exp = 0;
/*  71 */     this.level = 100;
/*  72 */     this.totalExp = GameConstants.getTraitExpNeededForLevel(this.level);
/*  73 */     this.localTotalExp = this.totalExp;
/*  74 */     return (this.level > oldLevel);
   }

   public int getLevel() {
/*  78 */     return this.level;
   }

   public void setLevel(int newLevel, MapleCharacter chr) {
/*  82 */     if (newLevel <= this.level) {
       return;
     }
/*  85 */     this.totalExp = GameConstants.getTraitExpNeededForLevel(newLevel);
/*  86 */     this.localTotalExp = this.totalExp;
/*  87 */     recalcLevel();
   }

   public int getExp() {
/*  91 */     return this.exp;
   }

   public void setExp(int exp) {
/*  95 */     this.totalExp = exp;
/*  96 */     this.localTotalExp = exp;
/*  97 */     recalcLevel();
   }

   public int getTotalExp() {
/* 101 */     return this.totalExp;
   }

   public int getLocalTotalExp() {
/* 105 */     return this.localTotalExp;
   }

   public void addLocalExp(int exp) {
/* 109 */     this.localTotalExp += exp;
   }

   public void clearLocalExp() {
/* 113 */     this.localTotalExp = this.totalExp;
   }

   public MapleTraitType getType() {
/* 117 */     return this.type;
   }
 }


/* Location:              C:\PGX\Server.jar!\client\MapleTrait.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */